/* 
Copyright DAUPHIN Maxime 2005

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
http://www.gnu.org/licenses/gpl.txt
*/
#ifndef __CLIPBOARD_H__
#define __CLIPBOARD_H__
#include <shlobj.h>
#include "Gui.h"
#include "Any.h"

namespace Gui {

class DropFile : public Object
{
	bool m_bCreate;
	std::vector<STRING>::iterator m_it;
	std::vector<STRING>	m_files;
public:
	DropFile(){ 
		m_bCreate = false; 
		m_it = m_files.begin(); 
	};
	DropFile(const DropFile& drop) 
	{
		m_it = drop.m_it; 
		m_bCreate = drop.m_bCreate; 
		m_files = drop.m_files;
	}
	~DropFile() {};
	void create(HDROP hDrop) 
	{ 
		assert(hDrop); 
		m_bCreate = true;
		uint nbFiles = ::DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0 );
		for ( uint i=0; i<nbFiles; i++)
		{
			//retrieve filename size
			UINT size = ::DragQueryFile( hDrop, i, NULL, 0 );
			char *pFileName = new char[size+1];
			//retrieve filename 
			UINT ret = ::DragQueryFile( hDrop, i, pFileName, size+1 );
			m_files.push_back( pFileName );
			delete []pFileName;
		}

	}
	uint getNbFile(void)
	{
		assert(m_bCreate);
		//assert(m_hDrop);
		//Retreive Number of file
		return (uint)m_files.size();
		//return ::DragQueryFile( m_hDrop, 0xFFFFFFFF, NULL, 0 );	
	}
	void resetIterator(void) { m_it = m_files.begin(); }
	STRING getNextFile(void)
	{
		if ( m_it == m_files.end() )
			return _T("");
		STRING ret = *m_it;
		m_it++;
		return ret;
	}
	STRING getFiles(void)
	{
		STRING ret;
		std::vector<STRING>::iterator it;
		for ( it = m_files.begin(); it != m_files.end(); it++ )
		{
			ret += (*it);
			ret += '\0';
		}
		return ret;
	}

};

class ClipBoard : public Object
{
	Wnd		*m_pWnd;
	HWND	m_hWndNextViewer;
	bool	m_bDisableNext;
public:
	ClipBoard(void);
	~ClipBoard(void);
	void create(Wnd *pWnd);
	Any onDrawClipBoard(UINT &uFormat);
	UINT enumClipboardFormats(UINT uFormat);
	HANDLE setClipboardData(UINT uFormat, HANDLE hMem);
	bool setData( uint uFormat, const Any &any );
	void disableNext(void);
};

class ClipBoardError{};

}; //End namespace Gui

#endif //__CLIPBOARD_H__
